from PySFML import sf

class camera (object) :
    __shared_state = {}
    def setup (self, (cam_x, cam_y) , (world_x, world_y) , caption):
        self.__dict__ = self.__shared_state
        self.caption = caption
        self.screen = sf.RenderWindow(sf.VideoMode(cam_x, cam_y), caption)
        self.x, self.y = cam_x, cam_y
        self.v_x, self.v_y = 0.0 , 0.0
        self.a_x, self.a_y = 0.0 , 0.0
        self.world_x, self.world_y = world_x, world_y
        self.pos_x, self.pos_y = 0 , 0
        self.screen.SetFramerateLimit (60)
        self.black = sf.Color (0,0,0)
    def __init__ (self) :
        self.__dict__ = self.__shared_state
    def get_world (self) :
        return self.world_x, self.world_y
    def get_cam (self) :
        return self.x, self.y
    def get_cam_pos (self) :
        return self.pos_x, self.pos_y
    def draw_sprite (self, sprite) :
        sprite.SetPosition (sprite.x - self.pos_x, sprite.y - self.pos_y)
        self.screen.Draw (sprite)
    def draw_sprite_ignore (self, sprite) :
        sprite.SetPosition (sprite.x, sprite.y)
        self.screen.Draw (sprite)
    def draw_shape_ignore (self, shape) :
        self.screen.Draw (shape)
    def get_events (self, event) :
        return self.screen.GetEvent (event)
    def resize (self, x, y) :
        self.screen.Create (sf.VideoMode(x , y), self.caption)
    def get_input (self) :
        return self.screen.GetInput ()
    def draw_text_ignore (self, text) :
        self.screen.Draw (text)
    def set_position (self,x, y) :
        if x != None :
            self.pos_x = x
        if y != None :
            self.pos_y = y
    def center (self, new_x, new_y) :
        self.pos_x = new_x - (self.x / 2)
        self.pos_y = new_y - (self.y / 2)
    def set_velocity (self, x, y) :
        if x != None :
            self.v_x = x
        if y != None :
            self.v_y = y
    def set_acceleration (self, x, y) :
        if x != None :
            self.a_x = x
        if y != None :
            self.a_y = y
    def clear (self) :
        self.screen.Clear (self.black)
    def update (self, dt) : 
        dt_secs = float (dt) / 1000
        self.pos_x += self.v_x * dt_secs
        self.pos_y += self.v_y * dt_secs
        self.v_x += self.a_x * dt_secs
        self.v_y += self.a_y * dt_secs
        if (self.v_x > -10) & (self.v_x < 10) :
            self.v_x = 0
            self.a_x = 0
        if (self.v_y > -10) & (self.v_y < 10) :
            self.v_y = 0
            self.a_y = 0
        if self.pos_x < 0 :
            self.pos_x = 0
            self.v_x = 0
            self.a_x = 0
        if self.pos_y < 0 :
            self.pos_y = 0
            self.v_y = 0
            self.a_y = 0
        if self.pos_x > self.world_x - self.x :
            self.pos_x = self.world_x - self.x
            self.v_x = 0
            self.a_x = 0
        if self.pos_y > self.world_y - self.y :
            self.pos_y = self.world_y - self.y
            self.v_y = 0
            self.a_y = 0
    def display (self) :
        self.screen.Display ()
    def move (self,x , y) :
        if x != None :
            self.pos_x += x
        if y != None :
            self.pos_y += y
